package org.galaxyworld.flycode.core;

import org.apache.commons.io.FileUtils;
import org.galaxyworld.flycode.config.AppConfigData;
import org.galaxyworld.flycode.config.ConfigManager;

import java.io.File;
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;

public class Application {

    private List<Job> jobList;

    public static Application getInstance() {
        return ApplicationSingleton.INSTANCE;
    }

    public void addJob(Job job) {
        jobList.add(job);
    }

    public void startAll() {
        for (Job job : jobList) {
            job.exec();
        }
    }

    private Application() {
        AppConfigData appConfigData = ConfigManager.getConfig(AppConfigData.class);
        String outputDir = appConfigData.getOutputDirPath();
        try {
            FileUtils.forceMkdir(new File(outputDir));

            jobList = new LinkedList<>();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private static class ApplicationSingleton {
        public static final Application INSTANCE = new Application();
    }

}
